#include "zglTexture.h"
#include "zglEngine.h"

#pragma warning (push)
#pragma warning (disable : 4996)

#include "sStrings.h"

namespace sgui
{
namespace engine
{

void zglTexture::draw(const math::sRectf& rect) const
{
	if (m_tex)
    {
		ssprite2d_Draw(m_tex, rect.X, rect.Y, rect.W, rect.H, 0, 255);
    }
}

void zglTexture::drawClip(const math::sRectf& rect, const math::sRectf& clipRect) const
{
	if (m_tex)
    {
		csprite2d_Draw(m_tex, rect.X, rect.Y, rect.W, rect.H, 0, m_engine.toRect(clipRect));
    }
}
	
void zglTexture::update(const preset::sPreset& preset)
{
	//
}

zglTexture::zglTexture(zglEngine& engine, const res::sTextureResource& res, const preset::sTexturePreset& preset) :
	sTexture(engine, res, preset), m_tex(NULL), m_engine(engine)
{
	if (!res.getContents().empty())
	{
		const sgui::res::sResourceContent* cnt = res.getContents()[0];
		if (cnt)
		{
			std::string fileName = wstring_to_string(cnt->getExtention());

			zglTMemory mem;
			mem.Memory = cnt->getData();
			mem.Position = 0;
			mem.Size = cnt->getDataSize();

			m_tex = tex_LoadFromMemory(mem, fileName.c_str());
		}
	}
}

};
};

#pragma warning (pop)